package com.ruoyi.web.controller.compensationManagement;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.compensationManagement.domain.CompensationRetirespayroll;
import com.ruoyi.compensationManagement.service.ICompensationRetirespayrollService;
import com.ruoyi.system.service.ISysCommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 退休人员补贴工资账单Controller
 *
 * @author zy
 * @date 2022-10-08
 */
@RestController
@RequestMapping("/compensationManagement/viewSelfRetiresPayroll")
public class CompensationViewSelfRetirespayrollController extends BaseController {
    @Autowired
    private ICompensationRetirespayrollService compensationRetirespayrollService;

    @Autowired
    private ISysCommonService sysCommonService;

    /**
     * 查询自身补贴工资列表
     */
    @PreAuthorize("@ss.hasPermi('compensationManagement:viewSelfRetiresPayroll:list')")
    @GetMapping("/list")
    public TableDataInfo list(CompensationRetirespayroll compensationRetirespayroll) {
        startPage();
        compensationRetirespayroll.setJobNumber(sysCommonService.getSysUserByUserId(getUserId()).getJobNumber());
        compensationRetirespayroll.setAuditStatus(1);
        List<CompensationRetirespayroll> list = compensationRetirespayrollService.selectCompensationRetirespayrollList(compensationRetirespayroll);
        return getDataTable(list);
    }

    /**
     * 获取自身补贴工资详细信息
     */
    @PreAuthorize("@ss.hasPermi('compensationManagement:viewSelfRetiresPayroll:query')")
    @GetMapping(value = "/{retireespayrollId}")
    public AjaxResult getInfo(@PathVariable("retireespayrollId") Long retireespayrollId) {
        CompensationRetirespayroll compensationRetirespayroll = new CompensationRetirespayroll();
        compensationRetirespayroll.setRetireespayrollId(retireespayrollId);
        compensationRetirespayroll.setJobNumber(sysCommonService.getSysUserByUserId(getUserId()).getJobNumber());
        if (compensationRetirespayrollService.isItSelfRetireesPayroll(compensationRetirespayroll) > 0) {
            Map<String, Object> map = new HashMap<>();
            //获取固定项目
            map.put("fixedItems", compensationRetirespayrollService.selectCompensationRetirespayrollByRetireespayrollId(retireespayrollId));
            //获取浮动项目
            map.put("floatingItems", compensationRetirespayrollService.selectfFoatingItemsByRetireespayrollId(retireespayrollId));
            return AjaxResult.success(map);
        } else {
            return AjaxResult.error("非法查询");
        }
    }
}
